<?php


include_once "funct.php";

if (!isset($_POST["id"], $_POST["valoare"]))
	iesire();

clean($_POST["id"]);
clean($_POST["valoare"]);

switch ($_POST["id"]) {
	case "nume": {
			if (strlen($_POST["valoare"]) > 4) {
				$rezultat = mysql_query("select * from " . $db["users"] . " where name='" . $_POST["valoare"] . "'");
				if (mysql_num_rows($rezultat) == 0)
					echo "1";
				else
					echo "0";
			}
			else
				echo "0";
			break;
		}
	case "parola1": {
			$_SESSION["parola1"] = $_POST["valoare"];
			if (strlen($_POST["valoare"]) > 4) {
				if (isset($_SESSION["parola2"], $_SESSION["parola1"])) {
					if ($_SESSION["parola1"] == $_SESSION["parola2"])
						echo "1";
					else
						echo "0";
				}
				else
					echo "1";
			}
			else
				echo "0";
			break;
		}
	case "parola2": {
			$_SESSION["parola2"] = $_POST["valoare"];
			if (strlen($_POST["valoare"]) > 4) {
				if (isset($_SESSION["parola2"], $_SESSION["parola1"])) {
					if ($_SESSION["parola1"] == $_SESSION["parola2"])
						echo "1";
					else
						echo "0";
				}
				else
					echo "0";
			}
			else
				echo "0";
			break;
		}
	case "mail": {
			if (strlen($_POST["valoare"]) > 4) {
				if (filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL)) {
					$rezultat = mysql_query("select * from " . $db["users"] . " where email='" . $_POST["valoare"] . "'");
					if (mysql_num_rows($rezultat) == 0)
						echo "1";
					else
						echo "0";
				}
				else
					echo "0";
			}
			else
				echo "0";
			break;
		}
	case "day": {
			$_SESSION["day"] = (int) ($_POST["valoare"]);
			if (isset($_SESSION["day"], $_SESSION["month"], $_SESSION["year"])) {
				if (is_numeric($_SESSION["day"]) && is_numeric($_SESSION["month"]) && is_numeric($_SESSION["year"]) && $_SESSION["day"] <= 32 && $_SESSION["month"] <= 12 && $_SESSION["year"] < 3000 && $_SESSION["year"]>1900) {
					$birday = $_SESSION["year"] . "-" . $_SESSION["month"] . "-" . $_SESSION["day"];
					$time = strtotime(ceas()) - strtotime($birday);
					if ($time > (60 * 60 * 24 * 365 * 12))
						$ok = 1;
					else
						$ok = 0;
					echo $ok;
				}
				else
					echo "0";
			}
			else
				echo "0";
			break;
		}
	case "month": {
			$_SESSION["month"] = (int) ($_POST["valoare"]);
			if (isset($_SESSION["day"], $_SESSION["month"], $_SESSION["year"])) {
				if (is_numeric($_SESSION["day"]) && is_numeric($_SESSION["month"]) && is_numeric($_SESSION["year"]) && $_SESSION["day"] <= 32 && $_SESSION["month"] <= 12 && $_SESSION["year"] < 3000 && $_SESSION["year"]>1900) {
					$birday = $_SESSION["year"] . "-" . $_SESSION["month"] . "-" . $_SESSION["day"];
					$time = strtotime(ceas()) - strtotime($birday);
					if ($time > (60 * 60 * 24 * 365 * 12))
						$ok = 1;
					else
						$ok = 0;
					echo $ok;
				}
				else
					echo "0";
			}
			else
				echo "0";
			break;
		}
	case "year": {
			$_SESSION["year"] = (int) ($_POST["valoare"]);
			if (isset($_SESSION["day"], $_SESSION["month"], $_SESSION["year"])) {
				if (is_numeric($_SESSION["day"]) && is_numeric($_SESSION["month"]) && is_numeric($_SESSION["year"]) && $_SESSION["day"] <= 32 && $_SESSION["month"] <= 12 && $_SESSION["year"] < 3000 && $_SESSION["year"]>1900) {
					$birday = $_SESSION["year"] . "-" . $_SESSION["month"] . "-" . $_SESSION["day"];
					$time = strtotime(ceas()) - strtotime($birday);
					if ($time > (60 * 60 * 24 * 365 * 12))
						$ok = 1;
					else
						$ok = 0;
					echo $ok;
				}
				else
					echo "0";
			}
			else
				echo "0";
			break;
		}
}
?>
